package com.hgsoft.dao;

import java.util.Date;
import java.util.List;

import org.hibernate.Query;
import org.springframework.stereotype.Repository;

import com.hgsoft.entity.SideDoorPf;
import com.hgsoft.util.DateUtil;

@Repository
public class SideDoorPfDao extends BaseDao<SideDoorPf> {

	public void delete(Date date) {
		StringBuffer sb = new StringBuffer();
		sb.append("DELETE FROM SideDoorPf WHERE date='").append(DateUtil.getDateStr(date)).append("' GROUP BY [date]");
		Query q = this.getSession().createQuery(sb.toString());
		q.executeUpdate();

	}
	
	@SuppressWarnings("unchecked")
	public List<Date> getExistDates(String year) {
		List<Date> list;
		StringBuffer sb = new StringBuffer();
		sb.append("SELECT [date] FROM tb_SideDoorPF WHERE DATEPART(yyyy, [date]) = '").append(year).append("' GROUP BY [date]");
		Query q = this.getSession().createSQLQuery(sb.toString());
		list = q.list();
		return list;
	}

	/*
	 * @SuppressWarnings("rawtypes") public List query(Pager pager, Integer
	 * line, Date date, String station) {
	 * 
	 * String sql =
	 * "SELECT sd.id, sd.date, sd.line, sd.station, sd.num FROM OPENQUERY(mysqllink,'select * from v_side_door') AS sd WHERE 1 = 1"
	 * ; if(line != null) { sql = sql + " AND sd.line = " + line; } if(date !=
	 * null) { sql = sql + " AND sd.date = '" + DateUtil.getDateStr(date) + "'";
	 * } if(station != null && !station.isEmpty()) { sql = sql +
	 * " AND sd.station like '%" + station + "%'"; }
	 * 
	 * sql = sql + " ORDER BY sd.date DESC, sd.line";
	 * 
	 * List list = this.query(pager, sql); return list; }
	 */

}
